import { selectionBoxMixin } from '../../common/mixins/selectionBox';
const name = 'grimm-checkbox';
export default {
  name,
  mixins: [selectionBoxMixin],
  props: {
    className: {
      default: name,
    },
    falseIcon: {
      type: String,
      default: 'checkbox',
    },
    trueIcon: {
      type: String,
      default: 'checkbox-active',
    },
  },
  computed: {
    _isChecked() {
      // const { value } = this.option
      /* eslint-disable eqeqeq */
      return (this.value || []).some(item =>
        this.strict ? item === this.name : item == this.name
      );
    },
  },
  methods: {
    _onInnerClick() {
      let checkedItems = (this.value || []).slice();
      if (this._isChecked) {
        /* eslint-disable eqeqeq */
        checkedItems = checkedItems.filter(item =>
          this.strict ? item !== this.name : item != this.name
        );
      } else {
        checkedItems.push(this.name);
      }
      this._onCheckboxIntercept(() => {
        this.$emit('input', checkedItems);
      }, checkedItems);
    },
  },
};
